﻿
@{
    ViewBag.Title = "岗位信息维护";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row">
    <div class="col-md-3">
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">模块按钮结构</h3>
                <div class="box-tools pull-right">
                    <a data-toggle="tooltip" title="刷新" class="btn btn-default btn-sm"><i class="fa fa-refresh">刷新</i></a>
                    <a class="btn btn-danger  btn-sm" data-widget="collapse" data-toggle="tooltip" title="伸缩" style="margin-right: 5px;"><i class="fa fa-minus"></i></a>
                </div>
            </div>
            <div class="box-body" id="tree-box-body" style="overflow: auto">
                <ul id="tree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="col-md-9">
    
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">岗位列表</h3>
                <div class="box-tools">
                    <div class="input-group" style="width: 250px;">
                        <input type="text" class="form-control input-sm" placeholder="请输入名称进行模糊查询...">
                        <div class="input-group-btn">
                            <a class="btn btn-sm btn-default"><i class="fa fa-search"></i></a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="box-body no-padding">
                <div class="mailbox-controls">
                    <div class="btn-group" id="partial_button_toolbar">
                        @{ Html.RenderPartial("~/Areas/Common/Views/Shared/_PartialButton.cshtml"); }
                    </div>
                    <a data-toggle="tooltip" title="刷新" class="btn btn-default btn-sm"><i class="fa fa-refresh">刷新</i></a>
                </div>
                <div class="mailbox-jqgrid">
                    <table id="list"></table>
                    <div id="pager"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        height = UtilWindowHeightWidth().WinH - 218;
        $("#tree-box-body").height(height);
        initGird();
        initTree();
        initTreeData();
    });

    var zNodes,
        treeObj,
        setting,
        $grid,
        height;

    //初始化表格
    function initGird() {
        $grid = $("#list").jgridview(
        {
            url: "/System/Post/GetPostByOrganizationId",
            multiselect: false,
            colModel: [
                { name: "PostId", hidden: true },
                { label: "代码", name: "Code", index: "PostCode", width: 100, fixed: true },
                { label: "名称", name: "Name", index: "PostName", width: 100, fixed: true },
                { label: "归属组织", name: "OrganizationName", width: 150, fixed: true },
                { label: "主联系人", name: "MainSupervisor", width: 50, fixed: true },
                { label: "联系方式", name: "MainSupervisorContact", width: 150, fixed: true },
                { label: "冻结", name: "IsFreeze", width: 50, align: "center", fixed: true, formatter: "YesOrNo" },
                { label: "排序", name: "OrderNo", index: "OrderNo", width: 50, align: "center", fixed: true, search: false },
                { label: "创建时间", name: "CreateTime", index: "u.CreateTime", width: 120, fixed: true },
                { label: "创建人员", name: "CreateUserName", width: 60, align: "center", fixed: true },
                { label: "最后修改时间", name: "UpdateTime", width: 120, align: "center", fixed: true },
                { label: "最后修改人员", name: "UpdateUserName", width: 60, align: "center", fixed: true },
                { label: "备注", name: "Remark", index: "Remark", width: 200, align: "center", fixed: true }
            ],
            postData: { Id: Language.common.guidempty },
            height: height - 100
        });
    }

    //初始化组织机构
    function initTree() {
        //配置
        setting = {
            view: {
                dblClickExpand: false,
                showLine: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            expandSpeed: "",
            callback: {
                onClick: onClickTree
            }
        };
    }

    //初始化树结构:同步
    function initTreeData() {
        UtilAjaxPostAsync("/System/Organization/GetOrganizationTree", null, function (data) {
            zNodes = data;
            treeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
            treeObj.expandAll(true);
        });
    }

    //获取表格数据
    function getGridData() {
        var treeNode = ZtreeGetSelectedNodes($.fn.zTree.getZTreeObj("tree"));
        var pId = Language.common.guidempty;
        if (treeNode.length !== 0) {
            pId = treeNode[0].id;
        }
        UtilAjaxPost("/System/Post/GetPostByOrganizationId", { Id: pId },
            function (data) {
                GridReloadLoadOnceData($grid, data);
            }
        );
    }

    //操作:新增
    function add() {
        var treeNode = ZtreeGetSelectedNodes($.fn.zTree.getZTreeObj("tree"));
        if (treeNode.length === 0) {
            DialogTipsMsgWarn("请选择需要添加岗位的组织机构", 2000);
            return;
        }
        ArtDialogOpen("/System/Post/Edit?organizationId=" + treeNode[0].id, "新增岗位", 590);
    }

    //操作:编辑
    function edit() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/System/Post/Edit?postId=" + info.PostId, "编辑岗位-" + info.Name, 590);
        });
    }

    //删除匹配项
    function del() {
        //查看是否选中
        GridIsSelect($grid, function () {
            ArtDialogConfirm(Language.common.deletemsg, function () {
                UtilAjaxPostWait(
                    "/System/Post/DeletePost",
                    { id: GridGetSingSelectData($grid).PostId },
                    perateStatus
                );
            });
        });
    }

    //树点击触发
    function onClickTree(e, treeId, treeNode) {
        //加载数据
        getGridData();
    }

    //请求完成
    function perateStatus(data) {
        DialogAjaxResult(data);
        if (data.ResultSign === 0) {
            getGridData();
        }
    }

    //加载页面数据
    function loadTreeAndGrid() {
        initTree();
        initTreeData();
        getGridData();
    }

    //岗位用户
    function postUser() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/Common/UserControl/PrivilegeMasterUser?" +
                "privilegeMaster=" + Language.privilegeMaster.post + "&" +
                "privilegeMasterValue=" + info.PostId,
                "维护岗位用户-" + info.Name, true, 450, 830);
        });
    }

    //模块权限
    function menuPermission() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/System/Permission/Menu?privilegeMasterValue=" + info.PostId + "&privilegeMaster=" + Language.privilegeMaster.post, "模块权限授权-" + info.Name, 380);
        });
    }

    //模块按钮权限
    function functionPermission() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/System/Permission/Function?privilegeMasterValue=" + info.PostId + "&privilegeMaster=" + Language.privilegeMaster.post, "模块按钮权限授权-" + info.Name, 810);
        });
    }

    //字段权限
    function fieldPermission() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/System/Permission/Field?privilegeMasterValue=" + info.PostId + "&privilegeMaster=" + Language.privilegeMaster.post, "字段权限授权-" + info.Name, 810);
        });
    }

    //数据权限
    function dataPermission() {
        //查看是否选中
        GridIsSelect($grid, function () {
            var info = GridGetSingSelectData($grid);
            ArtDialogOpen("/System/Permission/Data?privilegeMasterValue=" + info.PostId + "&privilegeMaster=" + Language.privilegeMaster.post, "数据权限授权-" + info.Name, 810);
        });
    }

</script>